package com.zhkj.txg.module.home.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.LogUtils
import com.youth.banner.adapter.BannerAdapter
import com.zhkj.txg.R
import com.zhkj.txg.module.home.entity.RecommendInfo

class HomeBannerRecommendAdapter(
    private val context: Context
) : BannerAdapter<MutableList<RecommendInfo>, BannerRecommendViewHolder>(null) {


    override fun onCreateHolder(parent: ViewGroup?, viewType: Int): BannerRecommendViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_home_banner_recommend, parent, false).apply {
            layoutParams =
                ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
        }
        return BannerRecommendViewHolder(view)
    }

    override fun onBindView(holder: BannerRecommendViewHolder, data: MutableList<RecommendInfo>, position: Int, size: Int) {
//        holder?.let { ImageUtils.loadImage(context, it.img, data?.image ?: "") }
        val recommendAdapter = HomeRecommendAdapter()
        with(holder.recyclerBannerRecommend) {
            layoutManager =
                androidx.recyclerview.widget.GridLayoutManager(context, 3)
            addItemDecoration(
                com.zhkj.txg.utils.GridItemDecoration(
                    com.zhkj.lib.utils.ScreenUtil.dip(context, 5),
                    com.zhkj.lib.utils.ScreenUtil.dip(context, 5)
                )
            )
            adapter = recommendAdapter
        }
        recommendAdapter.setNewData(data)
    }

    fun clearData() {

    }
}

class BannerRecommendViewHolder(view: View) : RecyclerView.ViewHolder(view) {
    val recyclerBannerRecommend = itemView.findViewById<RecyclerView>(R.id.recyclerBannerRecommend)
}